package kingwing.dc.core.view.usersite;

import javax.annotation.Resource;

import kingwing.dc.core.model.Rule;
import kingwing.dc.core.model.RuleDetail;
import kingwing.dc.core.orm.hibernate.CommonHibernateDao;

import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import com.bstek.bdf2.core.context.ContextHolder;
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.data.provider.Criteria;
import com.bstek.dorado.data.provider.Page;

@Component
public class UserSiteManagePR {
	
	@Resource(name=CommonHibernateDao.BEAN_ID)
	private CommonHibernateDao commonHibernateDao;
	
	/**
	 * 根据规则ID分页获取规则明细
	 * @param pages
	 * @param id
	 */
	@DataProvider
	public void getRuleDetailforPages(Page<RuleDetail> pages,String id){
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(RuleDetail.class);
		if (StringUtils.isNotBlank("id")) {
			detachedCriteria.add(Restrictions.eq("ruleId", id));
		}
//		detachedCriteria.add(Restrictions.eq("createUserId", ContextHolder.getLoginUserName()));
		detachedCriteria.add(Restrictions.not(Restrictions.eq("createUserId", ContextHolder.getLoginUserName())));

		this.commonHibernateDao.pagingQuery(pages, detachedCriteria);
	}
	
	/**
	 * 分页获取所有的规则
	 * @return
	 */
	@DataProvider
	public void  getRulePage(Page<Rule> page,Criteria criteria){
		DetachedCriteria detachedCriteria = this.commonHibernateDao.buildDetachedCriteria(criteria, Rule.class);
//		detachedCriteria.add(Restrictions.eq("createUserId", ContextHolder.getLoginUserName()));
		detachedCriteria.add(Restrictions.not(Restrictions.eq("createUserId", ContextHolder.getLoginUserName())));
		detachedCriteria.add(Restrictions.not(Restrictions.eq("createUserId", ContextHolder.getLoginUserName())));
		this.commonHibernateDao.pagingQuery(page, detachedCriteria);
	}

}
